package com.neuedu.javase.api;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-28 10:35
 * 描述 :
 */
public class MyObject {
    public static void main(String[] args) {

        Object obj1 = new String("abc");  // [a b c]
        Object obj2 = new String("abc");  // [a b c]


        System.out.println(obj1 == obj2);  //false

        //字符串使用equals 判断是否字面量相同
        System.out.println("obj1.equals(obj2) = " + obj1.equals(obj2));


        System.out.println("obj1.hashCode() = " + obj1.hashCode());
        System.out.println("obj2.hashCode() = " + obj2.hashCode());


        HashSet hashSet = new HashSet();
        hashSet.add(obj1);
        hashSet.add(obj2);


        System.out.println("hashSet.size() = " + hashSet.size());


        HashMap map = new HashMap();
        map.put(obj1,"111111");
        map.put(obj2,"222222");
        map.put(new String("def"),"222222");
        map.put(new String("qqqq"),"3333333");

        System.out.println("map.size() = " + map.size());  // 2


        System.out.println("obj1.toString() = " + obj1.toString());


        User user1 = new User("张三");
        User user2 = new User("李四");

        System.out.println("user1 = " + user1);  //打印对象，相当于是toString
        System.out.println("user2 = " + user2);

        System.out.println("user1 = " + user1.toString());  // 类名（全限定名）+@+ 十六进制（hashcode）
        System.out.println("user2 = " + user2.toString());


    }
}
